#define DEBUG
#include <cstdio>

using namespace std;

const int maxn=500000;

int min(int a, int b) {
  return a<b ? a : b;
}

int max(int a, int b) {
  return a>b ? a : b;
}

class SegmentTree {
public:
  int lc[4*maxn+1], rc[4*maxn+1], v[4*maxn+1], mark[4*maxn+1];

  void markDown(int o, int l, int r) {
    if (mark[o]!=0) {
      if (l!=r) {
	mark[o*2]=mark[o*2+1]=mark[o];
      }
      lc[o]=rc[o]=mark[o];
      v[o]=1;
      mark[o]=0;
    }
  }

  void set(int o, int l, int r, int tl, int tr, int tc) {
    markDown(o, l, r);
    if (l==tl && r==tr) {
      mark[o]=tc;
      markDown(o, l, r);
    } else {
      int mid=(l+r)/2;
      if (tl<=mid && tr>=l) {
	set(o*2, l, mid, max(tl, l), min(tr, mid), tc);
      }
      if (tl<=r && tr>mid) {
	set(o*2+1, mid+1, r, max(tl, mid+1), min(tr, r), tc);
      }
      markDown(o*2, l, mid), markDown(o*2+1, mid+1, r);
      lc[o] = lc[o*2], rc[o] = rc[o*2+1];
      v[o]=v[o*2]+v[o*2+1]-(rc[o*2]==lc[o*2+1]);
    }
  }

  int get(int o, int l, int r, int tl, int tr) {
    markDown(o, l, r);
    if (l==tl && r==tr) {
      return v[o];
    } else {
      int mid=(l+r)/2, ret=0;
      if (tl<=mid && tr>mid) {
	ret = get(o*2, l, mid, max(tl, l), min(tr, mid))+get(o*2+1, mid+1, r, max(tl, mid+1), min(tr, r))-(rc[o*2]==lc[o*2+1]);
      } else if (tl<=mid && tr>=l) {
	ret = get(o*2, l, mid, max(tl, l), min(tr, mid));
      } else if (tl<=r && tr>mid) {
	ret = get(o*2+1, mid+1, r, max(tl, mid+1), min(tr, r));
      }
      return ret;
    }
  }

  int getColor(int o, int l, int r, int t) {
    markDown(o, l, r);
    if (l==r) {
      return lc[o];
    } else {
      int mid=(l+r)/2;
      if (t<=mid) {
	return getColor(o*2, l, mid, t);
      } else {
	return getColor(o*2+1, mid+1, r, t);
      }
    }
  }
} sgt;

bool rev=false;
int offset=0, n;

int transpos(int x) {
  return rev ? ((n+1-x)%n+offset)%n+1 : (x+offset-1)%n+1;
}

void swap(int x, int y) {
  int posx=transpos(x), posy=transpos(y), cx, cy;
  cx=sgt.getColor(1, 1, n, posx);
  cy=sgt.getColor(1, 1, n, posy);
  sgt.set(1, 1, n, posx, posx, cy);
  sgt.set(1, 1, n, posy, posy, cx);
}

void paint(int x, int y, int z) {
  int posx=transpos(x), posy=transpos(y);
  if (rev) {
    int temp;
    temp=posx, posx=posy, posy=temp;
  }
  if (posx<=posy) {
    sgt.set(1, 1, n, posx, posy, z);
  } else {
    sgt.set(1, 1, n, posx, n, z);
    sgt.set(1, 1, n, 1, posy, z);
  }
}

int count() {
  int ret=sgt.get(1, 1, n, 1, n);
  if (sgt.lc[1]==sgt.rc[1] && ret>1) {
    ret--;
  }
  return ret;
}

int countSegment(int x, int y) {
  int posx=transpos(x), posy=transpos(y);
  if (rev) {
    int temp;
    temp=posx, posx=posy, posy=temp;
  }
  int ret=0;
  if (posx<=posy) {
    ret = sgt.get(1, 1, n, posx, posy);
  } else {
    ret = sgt.get(1, 1, n, posx, n)+sgt.get(1, 1, n, 1, posy)-(sgt.lc[1]==sgt.rc[1]);
  }
  return ret;
}

int main() {
#ifdef DEBUG
  freopen("1214.in", "r", stdin);
  freopen("1214.out", "w", stdout);
#endif

  int c, q;
  scanf("%d %d", &n, &c);
  for (int i=1; i<=n; i++) {
    int x;
    scanf("%d", &x);
    sgt.set(1, 1, n, i, i, x);
  }

  scanf("%d", &q);
  for (int i=1; i<=q; i++) {
    char c;
    scanf(" %c", &c);
    if (c=='R') {
      int k;
      scanf("%d", &k);
      offset = rev ? (offset+k)%n : (offset-k+n)%n;
    } else if (c=='F') {
      rev = !rev;
    } else if (c=='S') {
      int i, j;
      scanf("%d %d", &i, &j);
      swap(i, j);
    } else if (c=='P') {
      int i, j, x;
      scanf("%d %d %d", &i, &j, &x);
      paint(i, j, x);
    } else if (c=='C') {
      scanf("%c", &c);
      if (c=='S') {
	int x, y;
	scanf("%d %d", &x, &y);
	printf("%d\n", countSegment(x, y));
      } else {
	printf("%d\n", count());
      }
    }
  }

  fclose(stdin);
  fclose(stdout);
  return 0;
}
